package main

import (
	"fmt"
	"jdzPackage/08-interface/empty"
)

type FileType int

const (
	CSV FileType = iota
	EXCEL
)

type ProcessStrategy interface {
	ProcessFile(filePath string)
}

func (c *CSVProcessor) ProcessFile(filePath string) {
	fmt.Println("Processing CSV file:", filePath)
}

type CSVProcessor struct {
}

func (c *ExcelProcessor) ProcessFile(filePath string) {
	fmt.Println("Processing Excel file:", filePath)
}

type ExcelProcessor struct {
}

type FileProcessor struct {
	filePath string
	strategy ProcessStrategy
}

func (fp *FileProcessor) ProcessFile() {
	fp.strategy.ProcessFile(fp.filePath)
}

var strategyMap = map[FileType]ProcessStrategy{
	CSV:   &CSVProcessor{},
	EXCEL: &ExcelProcessor{},
}

func NewFileProcessor(filePath string, fileType FileType) (*FileProcessor, error) {
	strategy, ok := strategyMap[fileType]
	if !ok {
		return nil, fmt.Errorf("Invalid file type: %s", fileType)
	}
	return &FileProcessor{
		filePath: filePath,
		strategy: strategy,
	}, nil
}

func main() {
	fileProcessor, err := NewFileProcessor("file.csv", CSV)
	if err != nil {
		fmt.Println(err)
		return
	}
	fileProcessor.ProcessFile()

	fileProcessor, err = NewFileProcessor("file.xlsx", EXCEL)
	if err != nil {
		fmt.Println(err)
		return
	}
	fileProcessor.ProcessFile()
	empty.EmptyInterface()
}
